package online.westonline.com.westonline.utils;

import android.database.sqlite.SQLiteDatabase;
import com.grandbroad.online.greendao.DaoMaster;
import com.grandbroad.online.greendao.DaoSession;

import online.westonline.com.westonline.MyApplication;

/**
 * 数据库工具
 * Created by xiatao on 2018/6/11.
 */

public class GreenDaoUtils
{
    private static volatile GreenDaoUtils instance;
    private DaoSession daoSession;
    private DaoMaster.DevOpenHelper helper;
    private DaoMaster daoMaster;
    private SQLiteDatabase db;
    public static GreenDaoUtils getInstance()
    {
        if (instance==null)
        {
            synchronized (GreenDaoUtils.class)
            {
                if (instance==null)
                {
                    instance = new GreenDaoUtils();
                }
            }
        }
        return instance;
    }

    /**
     * 获取数据库会话
     * @return
     */
    public DaoSession getDaoSession()
    {
        helper = new DaoMaster.DevOpenHelper(MyApplication.getContext(),"sport-db",null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
        return daoSession;
    }


}
